﻿ //using System;
//using System.Runtime.Serialization;
//using System.ServiceModel.Description;
//using LinFu.IoC.Configuration;
//using LinFu.IoC;
//namespace CoreEx.ServiceModel.Implementation
//{
//    /// <summary>
//    /// This class is used to replace the default <see cref="DataContractSerializerOperationBehavior"/> which 
//    /// controls the type of <see cref="XmlObjectSerializer"/> to be used for serialization and deserialization operations.
//    /// </summary>
//    /// <remarks>
//    /// If you need to replace the default serializer (<see cref="DataContractSerializer"/>)
//    /// you need to create a class that inherits from the <see cref="DataContractSerializerOperationBehavior"/> class.    
//    /// </remarks>
//    /// <example>
//    /// The following example shows how to implement a <see cref="DataContractSerializerOperationBehavior"/>
//    /// that creates a <see cref="NetDataContractSerializer"/>
//    /// <code>
//    /// <![CDATA[
//    ///    [Implements(typeof(DataContractSerializerOperationBehavior))]
//    ///    public class NetDataContractSerializerServiceBehavior :DataContractSerializerOperationBehavior
//    ///    {
//    ///        public NetDataContractSerializerServiceBehavior(OperationDescription operation) : base(operation) { }
//    ///        
//    ///       
//    ///        public override XmlObjectSerializer CreateSerializer(Type type, string name, string ns, IList<Type> knownTypes)
//    ///        {
//    ///            return new NetDataContractSerializer();
//    ///        }
//    ///
//    ///        public override XmlObjectSerializer CreateSerializer(Type type, System.Xml.XmlDictionaryString name, System.Xml.XmlDictionaryString ns, IList<Type> knownTypes)
//    ///        {
//    ///            return new NetDataContractSerializer();
//    ///        }
//    ///    }
//    /// ]]>
//    /// </code>
//    /// </example>
//    [Implements(typeof(IInitializer<OperationDescription>), ServiceName = "SerializerOperationInitializer")]
//    public class SerializerOperationInitializer : InitializerBase<OperationDescription>
//    {
//        /// <summary>
//        /// Replaces the default <see cref="DataContractSerializerOperationBehavior"/> with 
//        /// a custom <see cref="DataContractSerializerOperationBehavior"/> implementation.          
//        /// </summary>
//        /// <param name="operationDescription">The target contract operation.</param>
//        public override void Initialize(OperationDescription operationDescription)
//        {
//            if (ServiceContainer.Contains(typeof(DataContractSerializerOperationBehavior), Type.EmptyTypes))
//            {
//                var dataContractSerializerOperationBehavior =
//                    operationDescription.Behaviors.Find<DataContractSerializerOperationBehavior>();

//                if (dataContractSerializerOperationBehavior != null)
//                {
//                    var index = operationDescription.Behaviors.IndexOf(dataContractSerializerOperationBehavior);
//                    operationDescription.Behaviors.RemoveAt(index);
//                    dataContractSerializerOperationBehavior =
//                        ServiceContainer.GetService<DataContractSerializerOperationBehavior>(operationDescription);
//                    operationDescription.Behaviors.Insert(index, dataContractSerializerOperationBehavior);
//                }
//            }
//        }
//    }
//}
